package cn.edu.zhku.citrusmonitor.announcement.service;

import java.sql.SQLException;
import java.util.List;

import cn.edu.zhku.citrusmonitor.announcement.dao.AnnouncementDao;
import cn.edu.zhku.citrusmonitor.announcement.dao.AnnouncementDaoImpl;
import cn.edu.zhku.citrusmonitor.domain.TbAnnouncement;
import cn.edu.zhku.citrusmonitor.util.PageBean;


public class AnnouncementServiceImpl implements AnnouncementService{
	AnnouncementDao annd=new AnnouncementDaoImpl();
	@Override
	public int addAnnounce(TbAnnouncement announce) throws SQLException {
		return annd.addAnnounce(announce);
	}

	@Override
	public int removeAnnounce(String announcement_id) throws SQLException {
		
		return annd.removeAnnounce(announcement_id);
	}

	@Override
	public int modifyAnnounce(TbAnnouncement announce) throws SQLException {
		return annd.modifyAnnounce(announce);
	}

	@Override
	public List<TbAnnouncement> findAnByWord(String content) throws SQLException {
		return annd.findAnByWord(content);
	}

	@Override
	public List<TbAnnouncement> showAnnounce(int pageSize) throws SQLException {
		
		return annd.showAnnounce(pageSize);
	}

	@Override
	public TbAnnouncement showAnById(String announcementId) throws SQLException {
		TbAnnouncement announce=annd.showAnById(announcementId);
		
		
		return announce;
	}

	@Override
	public PageBean<TbAnnouncement> showAll(int currentPage, int pageSize) throws SQLException {
		
		int count=annd.count(null);
		int totalPage=(int) Math.ceil(count/pageSize);
		
		List<TbAnnouncement> announcelist=annd.showAll(currentPage,pageSize);
				
		PageBean<TbAnnouncement> pb=new PageBean<TbAnnouncement>();
		pb.setCount(count);
		pb.setCurrentPage(currentPage);
		pb.setPageSize(pageSize);
		pb.setTotalPage(totalPage);
		pb.setList(announcelist);
		
		return pb;
	}

	@Override
	public int delAll(String[] ids) throws SQLException {
		
		return annd.delAll(ids);
	}


}
